import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        String[] pp = str.split("-");
        String[] p1 = pp[0].split(" ");
        String[] p2 = pp[1].split(" ");
        String p = "345678910JQkA2";
        if(pp[0].equals("joker JOKER") || pp[1].equals("joker JOKER")){
            System.out.println("joker JOKER");
        }else if(p1.length == p2.length){
            if(p.indexOf(p1[0])>p.indexOf(p2[0])){
                System.out.println(pp[0]);
            }else{
                System.out.print(pp[1]);
            }
        }else if(p1.length == 4){
            System.out.println(pp[0]);
        }else if(p2.length == 4){
            System.out.println(pp[1]);
        }else{
            System.out.println("ERROR");
        }
    }
}




